

#import "FAMTabBarViewController.h"
#import "FAMTabBar.h"
@interface FAMTabBarViewController ()<FAMTabBarDelegate>
@property (nonatomic, strong)FAMTabBar *FAMMainTabBar;
@end

@implementation FAMTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBar.backgroundColor = kWhiteColor;
    [self FAM_setMainTabBar];
    [self FAM_setChildsViewController];
}
- (void)FAM_setMainTabBar{
    self.FAMMainTabBar = [FAMTabBar new];
    if (isIphoneX){
        self.FAMMainTabBar.frame = CGRectMake(0, 0, SCREEN_WIDTH, 84);
    }else{
        self.FAMMainTabBar.frame = CGRectMake(0, 0, SCREEN_WIDTH, 49);
    }
    self.FAMMainTabBar.delegate = self;
    [self.tabBar addSubview:self.FAMMainTabBar];
    [self.tabBar setBackgroundImage:[UIImage new]];
    [self.tabBar setShadowImage:[UIImage new]];
    self.tabBar.backgroundColor = kClearColor;
}
- (void)FAM_setChildsViewController{
    NSArray *normalImageArray = @[@"tabbar_home_normal",@"tabbar_mine_normal"];
    NSArray *selectedImageArray = @[@"tabbar_home_selected",@"tabbar_mine_selected"];
    FAMHomeViewController *genderViewController = [FAMHomeViewController new];
    FAMMineViewController *ageViewController = [FAMMineViewController new];
    NSArray *vcArray = @[genderViewController,ageViewController];
    for (int i = 0; i<vcArray.count; i++) {
        [self FAM_setChildVC:vcArray[i] title:nil image:normalImageArray[i] selectedImage:selectedImageArray[i]];
    }
}
- (void)FAM_setChildVC:(UIViewController *)vc title:(NSString *)title image:(NSString *)normalImage selectedImage:(NSString *)selectedImage{
    vc.tabBarItem.image = [UIImage imageNamed:normalImage];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
//    vc.tabBarItem.title = title;
    [self.FAMMainTabBar FAM_addTabBarButtonWithTabBarItem:vc.tabBarItem];
    [self addChildViewController:[[FAMNavigationViewController alloc]initWithRootViewController:vc]];
}
#pragma  mark --- FAMTabBarDelegate
- (void)FAMTabBar:(FAMTabBar *)tabBar didSelectedButtonFrom:(long)fromButtonTag to:(long)toButtonTag{
    self.selectedIndex = toButtonTag - 1000;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}
@end
